<style>
    .form-copy {
        margin-right: 5px;
        border-radius: 0;
        box-shadow: none;
        padding: 4px 12px 7px 12px;
        font-size: 14px;
        line-height: 1.42857143;
        color: #555;
        border: 1px solid #ccc;
        transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
    }
    .select2 {
        margin-right: 5px
    }
</style>

{{-- 行选操作 start --}}
<div class="btn-group">
    <a class="btn btn-sm btn-default">  {{ trans('admin.action') }}</a>
    <button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown">
        <span class="caret"></span>
        <span class="sr-only">Toggle Dropdown</span>
    </button>
    <ul class="dropdown-menu" role="menu">
        <li><a href="#" class="grid-batch">组合</a></li>
    </ul>
</div>
{{-- 行选操作 end --}}

<div class="btn-group" style="margin-right: 10px">
    <form class="form-inline" action="{{ $action }}" pjax-container method="get">
        <input style="width: 150px;" type="text" name="sku" value="{{ $filtersBlade['sku'] }}" class="form-copy" placeholder="SKU">
        <select id="classify_id" name="classify_id">
            {{ $filtersBlade['classify_id'] }}
        </select>
        <div class="input-group">
            <button style="margin-left: 10px;" class="btn btn-sm btn-info submit"><i class="fa fa-search"></i>&nbsp;&nbsp;{{ trans('admin.search') }}</button>
            <a style="margin-left: 10px;" href="{{ $action }}" class="btn btn-sm btn-default"><i class="fa fa-undo"></i>&nbsp;&nbsp;{{ trans('admin.reset') }}</a>
        </div>
    </form>
</div>
<script language="JavaScript" type="text/javascript">
    $(function () {
        $('#classify_id').select2({placeholder: '品类', allowClear: true, width: '150px'});
        $(".mix_num_").inputmask("integer",{
            onKeyValidation: function () {
                var max = $(this).data('max');
                if($(this).val() < 0 || isNaN($(this).val()) || $(this).val() > max){
                    $(this).val(max);
                }
            }
        });
        var selectedRows = function () {
            var param = {};
            var selected = [];
            var detail = {};
            $('.grid-row-checkbox:checked').each(function(index){
                var id = $(this).data('id');
                selected.push(id);
                var tr = $(this).closest('tr');
                var indexArr = {};
                indexArr['psku_id'] = id;
                indexArr['mix_num'] = tr.find('input[name="mix_num"]').val();
                detail[index] = indexArr;
            });
            param.selected = selected;
            param.detail = detail;
            return param;
        };

        $('.grid-batch').on('click', function() {
            var param = selectedRows();
            var ids = param.selected;
            if(ids.length == 0) {
                swal('请选择单据', '', 'error');
                return false;
            }
            var detail = param.detail;
            $.ajax({
                method: 'post',
                url: '/xqc/inventory/mix-ajax',
                data: {
                    _token:"{{ csrf_token() }}",
                    param: detail,
                    action: 'mixBatch'
                },
                success: function (data) {
                    if (typeof data === 'object') {
                        if (data.status) {
                            toastr.success('提交成功 !');
                            $.pjax.reload('#pjax-container');
                        } else {
                            swal(data.message, '', 'error');
                        }
                    }
                }
            });
        });
    });
</script>
